package com.tiny.mirror.service.product.application.convert;

import com.api.tiny.mirror.service.product.request.CreateAbilityRequest;
import com.api.tiny.mirror.service.product.request.UpdateAbilityRequest;
import com.api.tiny.mirror.service.product.response.AbilityVO;
import com.tiny.mirror.service.product.domain.ability.Ability;
import com.tiny.mirror.service.product.domain.ability.AbilityParams;
import com.tiny.mirror.service.product.infrastructure.entity.db.AbilityEntity;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/10/8
 */
@SuppressWarnings("CPD-START")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AbilityConvert {

  public static List<AbilityVO> convertToAbilityVOList(List<Ability> list) {
    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    return list.stream().map(l -> convertToAbilityVO(l)).collect(Collectors.toList());
  }

  public static List<AbilityVO> convertEntityListToAbilityVOList(List<AbilityEntity> list) {
    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    return list.stream().map(l -> convertToAbilityVO(l)).collect(Collectors.toList());
  }

  public static AbilityVO convertToAbilityVO(Ability item) {
    if (item == null) {
      return null;
    }
    AbilityVO result = new AbilityVO();
    result.setId(item.getId());
    result.setType(item.getType());
    result.setName(item.getName());
    result.setStatus(item.getStatus());
    result.setOrderNum(item.getOrderNum());
    result.setCreateTime(item.toEntity().getCreateTime());
    result.setUpdateTime(item.toEntity().getUpdateTime());
    return result;
  }

  public static AbilityVO convertToAbilityVO(AbilityEntity item) {
    if (item == null) {
      return null;
    }
    AbilityVO result = new AbilityVO();
    result.setId(item.getId());
    result.setType(item.getType());
    result.setName(item.getName());
    result.setStatus(item.getStatus());
    result.setOrderNum(item.getOrderNum());
    result.setCreateTime(item.getCreateTime());
    result.setUpdateTime(item.getUpdateTime());
    return result;
  }

  public static Ability convertToAbility(CreateAbilityRequest request) {
    if (request == null) {
      return null;
    }
    Ability result = new Ability();
    result.setType(request.getType());
    result.setName(request.getName());
    result.setStatus(request.getStatus());
    AbilityParams abilityParams = new AbilityParams();
    result.setParams(abilityParams);
    result.setOrderNum(request.getOrderNum());
    return result;
  }

  public static Ability convertToAbility(UpdateAbilityRequest request) {
    if (request == null) {
      return null;
    }
    Ability result = new Ability();
    result.setType(request.getType());
    result.setName(request.getName());
    result.setStatus(request.getStatus());
    result.setOrderNum(request.getOrderNum());
    return result;
  }
}
